import datetime

from flask import Flask,render_template,request
import datetime
# Flask  Jinja2  Werkzeug

# 初始化  让name =app
app = Flask(__name__)

#路由 通过路径匹配相应的函数
@app.route('/')
def hello_world():  # put application's code here
    return 'Hello!!!!!'

# render_template给用户渲染后的html
@app.route('/index')
def index():
    time=datetime.date.today() #普通变量
    task={"学校":"黑魔法烹饪学校","地点":"北极"} #数据字典
    return  render_template("index.html",var=time,list=["小明","小丽","小红"],task=task)

#表单提交
@app.route('/test/register')
def register():
    return  render_template("test/register.html")


#表单提交后跳转到result.html ，不加methods时，默认get
# 接收表单提交的路由，需要指定POST
@app.route("/result",methods=["POST","GET"])
def result():
    #把表单信息用request传过来
    if request.method=="POST":
        result_post=request.form #字典
        return  render_template("test/result.html",result_post=result_post)
# @app.route('/<name>')
# # 通过访问路径获取字符串参数
# # 获取name这个参数，加<>
# def name(name):  # put application's code here
#     return 'Hello! %s'%name
#
# @app.route('/id/<int:id>')
# # 通过访问路径获取整型
# def user_id(id):  # put application's code here
#     return 'Hello! %d user'%id



if __name__ == '__main__':
    app.run()
# Debug mode: off